<%@ page contentType="text/xml;charset=UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ page import="com.gzgi.framework.entity.*"%>
<%@ page import="com.gzgi.framework.tree.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.crm.model.*"%>
<%@ page import="org.apache.commons.lang.StringUtils"%>
<%
    Map params = RequestUtil.getParameterMap(request);
	//System.out.println(params);
	String actionType = request.getParameter("actionType");
	String code = request.getParameter("code");
	StringBuffer buffer = new StringBuffer();
	buffer.append("\n<rows>");
	SqlMapManager sqlMapManager = null;
	String statementId = null;
	List rows = null;
	try {
		sqlMapManager = (SqlMapManager) ContextFactory.getBean("sqlMapManager");

		if ("getAllCompanys".equals(actionType)) {
			statementId = "getAllCompanys";
		} else if ("getProjectsByCompanyId".equals(actionType)) {
			statementId = "getProjectsByCompanyId";
		} else if ("getLinkmansByCompanyId".equals(actionType)) {
			statementId = "getLinkmansByCompanyId";
		} else if ("getSalesByCompanyId".equals(actionType)) {
			statementId = "getSalesByCompanyId";
		} else if ("getSalesByProjectId".equals(actionType)) {
			statementId = "getSalesByProjectId";
		} else if ("getProductSeriesByModalityCode".equals(actionType)) {
			statementId = "getProductSeriesByModalityCode";
		} else if ("getProductBySeriesCode".equals(actionType)) {
			statementId = "getProductBySeriesCode";
		}

		Executor executor = new Executor();
		executor.setQuery(statementId);
		String[] values = { code };
		executor.setValues(values);

		rows = sqlMapManager.getList(executor);

		if (rows != null && rows.size() > 0) {
			Iterator iterator = rows.iterator();
			while (iterator.hasNext()) {
		      Object obj = iterator.next();

		if ("getAllCompanys".equals(actionType)) {
			if (obj instanceof Company) {
				Company x = (Company) obj;
				if (StringUtils.isEmpty(x.getCompanyName())) {
					continue;
				}
				buffer.append("\n  <item>");
				buffer.append("\n    <name>").append(
				x.getCompanyName()).append("</name>");
				buffer.append("\n    <value>").append(
				x.getCompanyId()).append("</value>");
				buffer.append("\n  </item>");
			}
		} else if ("getProjectsByCompanyId".equals(actionType)) {
			if (obj instanceof Project) {
				Project x = (Project) obj;
				if (StringUtils.isEmpty(x.getProjectName())) {
					continue;
				}
				buffer.append("\n  <item>");
				buffer.append("\n    <name>").append(
				x.getProjectName()).append("</name>");
				buffer.append("\n    <value>").append(
				x.getProjectId()).append("</value>");
				buffer.append("\n  </item>");
			}
		} else if ("getLinkmansByCompanyId".equals(actionType)) {
			if (obj instanceof Linkman) {
				Linkman x = (Linkman) obj;
				if (StringUtils.isEmpty(x.getName())) {
					continue;
				}
				buffer.append("\n  <item>");
				buffer.append("\n    <name>").append(
				x.getName()).append("</name>");
				buffer.append("\n    <value>").append(
				x.getLinkmanId()).append("</value>");
				buffer.append("\n  </item>");
			}
		}  else if ("getSalesByCompanyId".equals(actionType)) {
			if (obj instanceof SaleActor) {
				SaleActor x = (SaleActor) obj;
				if (StringUtils.isEmpty(x.getActorName())) {
					continue;
				}
				buffer.append("\n  <item>");
				buffer.append("\n    <name>").append(
				x.getActorName()).append("</name>");
				buffer.append("\n    <value>").append(
				x.getActorId()).append("</value>");
				buffer.append("\n  </item>");
			}
		} else if ("getSalesByProjectId".equals(actionType)) {
			if (obj instanceof SaleActor) {
				SaleActor x = (SaleActor) obj;
				if (StringUtils.isEmpty(x.getActorName())) {
					continue;
				}
				buffer.append("\n  <item>");
				buffer.append("\n    <name>").append(
				x.getActorName()).append("</name>");
				buffer.append("\n    <value>").append(
				x.getActorId()).append("</value>");
				buffer.append("\n  </item>");
			}
		} else if ("getProductSeriesByModalityCode"
				.equals(actionType)) {
			if (obj instanceof TreeNode) {
				TreeNode x = (TreeNode) obj;
				if (StringUtils.isEmpty(x.getName())) {
					continue;
				}
				buffer.append("\n  <item>");
				buffer.append("\n    <name>").append(
				x.getName()).append("</name>");
				buffer.append("\n    <value>").append(
				x.getCode()).append(
				"</value>");
				buffer.append("\n  </item>");
			}
		} else if ("getProductBySeriesCode".equals(actionType)) {
			if (obj instanceof TreeNode) {
				TreeNode x = (TreeNode) obj;
				if (StringUtils.isEmpty(x.getName())) {
					continue;
				}
				buffer.append("\n  <item>");
				buffer.append("\n    <name>").append(
				x.getName()).append("</name>");
				buffer.append("\n    <value>").append(
				x.getCode()).append("</value>");
				buffer.append("\n  </item>");
			}
		}
			}
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}

	buffer.append("\n</rows>");
	out.println(buffer.toString());
	//System.out.println(buffer.toString());
	out.flush();
%>